package com.example.dryyzx.dao;

import com.example.dryyzx.entity.BedRecord;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface BedRecordMapper {
    @Delete({
        "delete from bed_record",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into bed_record (id, bed_id, ",
        "customer_id, occupied_time, ",
        "leaving_time, enable)",
        "values (#{id,jdbcType=INTEGER}, #{bedId,jdbcType=INTEGER}, ",
        "#{customerId,jdbcType=INTEGER}, #{occupiedTime,jdbcType=TIMESTAMP}, ",
        "#{leavingTime,jdbcType=TIMESTAMP}, #{enable,jdbcType=BIT})"
    })
    int insert(BedRecord record);

    @InsertProvider(type=BedRecordSqlProvider.class, method="insertSelective")
    int insertSelective(BedRecord record);

    @Select({
        "select",
        "id, bed_id, customer_id, occupied_time, leaving_time, enable",
        "from bed_record",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bed_id", property="bedId", jdbcType=JdbcType.INTEGER),
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.INTEGER),
        @Result(column="occupied_time", property="occupiedTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="leaving_time", property="leavingTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    BedRecord selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, bed_id, customer_id, occupied_time, leaving_time, enable",
            "from bed_record",
            "where bed_id = #{bed_id,jdbcType=INTEGER} and customer_id = #{customer_id,jdbcType=INTEGER} and enable=1"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_id", property="bedId", jdbcType=JdbcType.INTEGER),
            @Result(column="customer_id", property="customerId", jdbcType=JdbcType.INTEGER),
            @Result(column="occupied_time", property="occupiedTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="leaving_time", property="leavingTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    BedRecord selectByBed_idAndCustomer_id(@Param("bed_id")Integer bed_id, @Param("customer_id")Integer customer_id);


    @UpdateProvider(type=BedRecordSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(BedRecord record);

    @Update({
        "update bed_record",
        "set bed_id = #{bedId,jdbcType=INTEGER},",
          "customer_id = #{customerId,jdbcType=INTEGER},",
          "occupied_time = #{occupiedTime,jdbcType=TIMESTAMP},",
          "leaving_time = #{leavingTime,jdbcType=TIMESTAMP},",
          "enable = #{enable,jdbcType=BIT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(BedRecord record);

    @Update({
            "update bed_record ",
            "set enable = 0",
            "where customer_id = #{customerId,jdbcType=INTEGER}"
    })
    int disableByCustomerId(Integer customerId);
}